package AndroidDocSync.frontend;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.InputType;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class login extends Activity {
	/** Called when the activity is first created. */

	public static final String LOG_TAG = "AndroidLogin";
	Button myButton;
	EditText myText;
	TextView myError;
	EditText myPasswd;
	String authToken = null;
	String email = null;
	String passwd = null;
	String list = null;
	boolean status = false;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		
		Log.v(LOG_TAG, "onCreate of login");
		Bundle listBundle = this.getIntent().getExtras();

		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		myButton = (Button) findViewById(R.id.mybutton);
		myText = (EditText) findViewById(R.id.txt_username);
		myError = (TextView) findViewById(R.id.lbl_err);
		myPasswd = (EditText) findViewById(R.id.txt_passwd);

		myText.setSingleLine();
		myText.setInputType(InputType.TYPE_NULL);
		// myPasswd.setInputType(InputType.TYPE_NULL);
		myError.setInputType(InputType.TYPE_NULL);

		Log.v(LOG_TAG, "Input value" + myText.toString());

		if (listBundle != null && listBundle.containsKey("log"))
			myError.setText(listBundle.getString("log"));

		/******* TEST CODE, REMOVE FOR FINAL DEMO **********/
/*		email = "207project@gmail.com";
		passwd = "207group04";
		
		Intent i = new Intent(login.this, showActionList.class);
		i.putExtra("user", email);
		i.putExtra("pwd", passwd);
		startActivity(i);
*/
		/****** ACTUAL CODE - REMOVE COMMENT TOKENS *******/
				
		myButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				myError.setText("");

				InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
				mgr.hideSoftInputFromWindow(myPasswd.getWindowToken(), 0);
				email = myText.getText().toString();
				Log.v(LOG_TAG, "email = " + email.toString());
				passwd = myPasswd.getText().toString();
				Log.v(LOG_TAG, "Password enterred");

				Intent i1 = new Intent(login.this, showActionList.class);
				i1.putExtra("user", email);
				i1.putExtra("pwd", passwd);
				startActivity(i1);

			}

		});

	}
}